package io.renren.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.dao.AutodecorategoodsdDao;
import io.renren.dto.AutodecorategoodsdDTO;
import io.renren.entity.AutodecorategoodsdEntity;
import io.renren.service.AutodecorategoodsdService;
import cn.hutool.core.util.StrUtil;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * ${comments}
 *
 * @author Sen 524227263@qq.com
 * @since 1.0.0 2024-05-30
 */
@Service
public class AutodecorategoodsdServiceImpl extends CrudServiceImpl<AutodecorategoodsdDao, AutodecorategoodsdEntity, AutodecorategoodsdDTO> implements AutodecorategoodsdService {

    @Override
    public QueryWrapper<AutodecorategoodsdEntity> getWrapper(Map<String, Object> params){
        String id = (String)params.get("id");

        QueryWrapper<AutodecorategoodsdEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StrUtil.isNotBlank(id), "id", id);

        return wrapper;
    }


    @Override
    public List<String> findGoodsMOIDByAutoDecorateMFk(String fk) {
        QueryWrapper<AutodecorategoodsdEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("AutoDecorateM_FK", fk);
        List<AutodecorategoodsdEntity> list = baseDao.selectList(wrapper);
        if (list != null && list.size() > 0) {
            return list.stream().map(AutodecorategoodsdEntity::getGoodsmFk).collect(Collectors.toList());
        }
        return Collections.emptyList();
    }
}